package com.pureut.production.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.pureut.common.security.utils.DictUtils;
import com.pureut.production.domain.WeighingFinishedMaterialProductDetail;
import com.pureut.production.domain.dto.WeighingFinishedMaterialProductDetailDto;
import com.pureut.production.mapper.WeighingFinishedMaterialProductDetailMapper;
import com.pureut.production.service.WeighingFinishedMaterialProductDetailService;
import com.pureut.system.api.domain.SysDictData;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/***
 * 成品称重表（物料明细table下）实现层
 * Author:C
 * Date:2023/02/24 16:09
 * @DESC
 */
@Service
public class WeighingFinishedMaterialProductDetailServiceImpl extends ServiceImpl<WeighingFinishedMaterialProductDetailMapper, WeighingFinishedMaterialProductDetail> implements WeighingFinishedMaterialProductDetailService {

    @Resource
    WeighingFinishedMaterialProductDetailMapper weighingFinishedMaterialProductDetailMapper;

    /**
     * 成品称重表（物料明细table下）列表
     *
     * @param productNumber
     * @return
     */
    @Override
    public List<WeighingFinishedMaterialProductDetailDto> getList(String productNumber) {
        //获取网型标准缓存字典数据
        List<SysDictData> netArray = DictUtils.getDictCache("sys_of_type");
        Map<String, String> netMap = netArray.stream().collect(Collectors.toMap(SysDictData::getDictValue, SysDictData::getDictLabel));

        List<WeighingFinishedMaterialProductDetailDto> list = weighingFinishedMaterialProductDetailMapper.getWeighingFinishedMaterialProductDetail(productNumber);

        for (WeighingFinishedMaterialProductDetailDto entity : list) {
            entity.setMaterialNetDict(netMap.get(entity.getMaterialNet()));
        }
        return list;
    }
}
